<template>
  <div class="menus-manage">
    <!-- 面包屑 -->
    <div class="bread-crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>资产列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="main-middle">
       <!-- <el-row :gutter="24">
        <el-col :span="12">
          <el-card class="never-card margin-b15" shadow="never">
            <div class="card-header">
              本月离职人员名单
            </div>
            <div class="card-body">
              <ul>
                <li v-for="datas in quitList" :key="datas.id">
                  <label><i class="fa fa-user" aria-hidden="true"></i> {{datas.userName}} </label>
                  <label><i class="fa fa-address-card" aria-hidden="true"></i> {{datas.userId}} </label>
                  <label><i class="fa fa-calendar" aria-hidden="true"></i> {{datas.date | filterTime }} </label>
                  <label data-clipboard-action="copy" class="copy" :data-clipboard-text="datas.userName" @click="copyLink">
                    <i class="fa fa-clipboard" aria-hidden="true"> 复制</i>
                  </label>
                </li>
              </ul>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
           <el-card class="never-card margin-b15" shadow="never">
            <div class="card-header">
              本月调岗人员名单
            </div>
            <div class="card-body">
              <ul>
                <li v-for="items in mobilizeList" :key="items.id">
                   <label><i class="fa fa-user" aria-hidden="true"></i> {{items.userName}} </label>
                  <label><i class="fa fa-address-card" aria-hidden="true"></i> {{items.userId}} </label>
                  <label><i class="fa fa-calendar" aria-hidden="true"></i> {{items.date | filterTime }} </label>
                  <label data-clipboard-action="copy" class="copy" :data-clipboard-text="items.userName" @click="copyLink">
                    <i class="fa fa-clipboard" aria-hidden="true"> 复制</i>
                  </label>
                </li>
              </ul>
            </div>
          </el-card>
        </el-col>
      </el-row> -->
      <el-card class="box-card">
        <!-- 查询条件 -->
        <el-row class="table-selbox" v-if="btnSel">
          <!-- 查询条件表单 -->
          <el-form :inline="true" :model="formInline">
              <!-- 所属公司 -->
            <el-form-item label="所属公司">
             <el-select v-model="formInline.compId" auto-complete="off" placeholder="请选择">
                <el-option label="无" value=""></el-option>
                <el-option
                  v-for="(item,index) in compList"
                  :key="index"
                  :label="item.compName"
                  :value="item.compId"
                ></el-option>
              </el-select>
            </el-form-item>
              <!-- 所属分类 -->
            <el-form-item label="所属分类">
              <el-select v-model="formInline.cateCode" filterable auto-complete="off" placeholder="请选择">
                <el-option label="无" value=""></el-option>
                <el-option
                  v-for="(item,index) in childrenList"
                  :key="index"
                  :label="item.cateName"
                  :value="item.cateCode"
                ></el-option>
              </el-select>
            </el-form-item>
            <!-- 资产编号 -->
            <el-form-item label="资产编号">
              <el-input v-model.trim="formInline.assetCode" clearable></el-input>
            </el-form-item>
             <!-- 资产名称 -->
            <el-form-item label="资产名称">
               <el-input v-model.trim="formInline.assetName" clearable></el-input>
            </el-form-item>
             <!-- 归属人 -->
            <el-form-item label="归属人员">
              <el-autocomplete
                v-model="formInline.user"
                :fetch-suggestions="querySearchAsync"
                placeholder="请输入姓名"
                @select="handleSelect"
                clearable
              >
                <template slot-scope="{ item }">
                  <div class="selName">
                    <span>{{ item.compName }} - {{ item.deptName }}</span>
                    <span>{{ item.userName }}</span>
                    <span>[{{ item.userId }}]</span>
                  </div>
                </template>
              </el-autocomplete>
            </el-form-item>
             <!-- 资产状态 -->
            <el-form-item label="资产状态">
              <el-select v-model="formInline.assetStatus">
                <el-option label="无" value=""></el-option>
                <el-option label="占用" value="1"></el-option>
                <el-option label="空闲" value="2"></el-option>
                <el-option label="维修" value="3"></el-option>
                <el-option label="报废" value="4"></el-option>
                <el-option label="停用" value="5"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="日期范围">
              <el-date-picker
                v-model="formInline.updateTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <!-- 搜索 -->
            <el-form-item>
              <el-button icon="el-icon-search" @click="selHandle">搜索</el-button>
            </el-form-item>
          </el-form>
        </el-row>
        <!-- 基本操作按钮 是否授权显示-->
        <el-row class="table-btns" v-if="[btnAdd,btnDel,btnUpload,btnDown].indexOf(true) > -1">
          <!-- 添加 -->
          <el-button
            v-if="btnAdd"
            type="success"
            size="medium"
            icon="el-icon-document-add"
            @click="addHandle"
          >添加</el-button>
          <!-- 删除 -->
          <el-button
            type="danger"
            size="medium"
            icon="el-icon-delete"
            @click="batchRemove"
            v-if="btnDel"
          >删除</el-button>

          <el-button type="primary" size="medium" style="float:right;" v-if="btnUpload" @click="showFile">
            <i class="fa fa-cloud-upload" aria-hidden="true"></i> 上传
          </el-button>
          <el-button type="success" size="medium" style="float:right;" v-if="btnDown" @click="getAssetExcel">
            <i class="fa fa-cloud-download" aria-hidden="true"></i> 下载
          </el-button>

        </el-row>
        <!-- 数据列表 -->
        <el-table
          :data="assetsData"
          border
          @selection-change="selsChange"
          style="width: 100%"
          height="520"
          ref="assetsData"
        >
          <!-- 全选 -->
          <el-table-column type="selection" width="40" align="center" fixed></el-table-column>
          <!-- 序号 -->
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <!-- 所属公司 -->
          <el-table-column :show-overflow-tooltip="true" prop="compName" label="所属公司" width="120" align="center" sortable></el-table-column>
          <!-- 所属类别 -->
          <el-table-column :show-overflow-tooltip="true" prop="cateName" label="所属分类" width="120" sortable></el-table-column>
          <!-- 资产编号 -->
          <el-table-column :show-overflow-tooltip="true" prop="assetCode" label="资产编号" width="200" sortable></el-table-column>
          <!-- 资产名称 -->
          <el-table-column :show-overflow-tooltip="true" prop="assetName" label="资产名称" width="150" sortable></el-table-column>
          <!-- 资产状态 -->
          <el-table-column align="center" label="状态" width="60">
            <template slot-scope="scope">
              <span v-if="scope.row.assetStatus === 1">
                占用
              </span>
              <span v-if="scope.row.assetStatus === 2">
                空闲
              </span>
              <span v-if="scope.row.assetStatus === 3">
                维修
              </span>
              <span v-if="scope.row.assetStatus === 4">
                报废
              </span>
              <span v-if="scope.row.assetStatus === 5">
                停用
              </span>
            </template>
          </el-table-column>
          <!-- 硬件编号 -->
          <el-table-column :show-overflow-tooltip="true" prop="hardwareCode" label="硬件编号" width="150" sortable></el-table-column>
          <!-- 归属人 -->
          <el-table-column align="center" label="归属人" width="150">
            <template slot-scope="scope">
              {{ scope.row.userName === null ? '' : scope.row.userName }}  [{{ scope.row.userId === '' ? '无' :  scope.row.userId }}]
            </template>
          </el-table-column>
          <!-- 资产放置地址 -->
          <el-table-column :show-overflow-tooltip="true" prop="address" label="放置地址" width="150" sortable></el-table-column>
          <!-- 购买时间 -->
          <el-table-column label="购买时间" width="120">
            <template slot-scope="scope">{{ scope.row.buyTime | filterTime }}</template>
          </el-table-column>
           <!-- 购买金额 -->
          <el-table-column label="购买金额" width="150">
            <template slot-scope="scope">
              ￥{{ scope.row.buyMoney }}元
            </template>
          </el-table-column>
          <!-- 创建时间 -->
          <el-table-column label="创建时间" width="180">
            <template slot-scope="scope">{{ scope.row.createTime | filterTimes }}</template>
          </el-table-column>
          <!-- 修改时间 -->
          <el-table-column label="修改时间" width="180">
            <template slot-scope="scope">{{ scope.row.updateTime | filterTimes }}</template>
          </el-table-column>
          <!-- 备注 -->
          <el-table-column :show-overflow-tooltip="true" prop="note" label="备注" width="150"></el-table-column>
          <!-- 操作列 -->
          <el-table-column
            label="管理"
            fixed="right"
            align="center"
            width="420"
            v-if="[btnDel,btnEdit].indexOf(true) > -1"
          >
            <template slot-scope="scope">
              <!-- 修改 -->
              <el-button size="mini" @click="editHandle(scope.row, 1)" v-if="btnEdit">修改</el-button>
              <!-- 状态 -->
              <el-button type="success" size="mini" @click="editHandle(scope.row, 2)" v-if="btnEdit">状态</el-button>
              <!-- 归属 -->
              <el-button type="warning" size="mini" @click="editHandle(scope.row, 3)" v-if="btnEdit">归属</el-button>
              <!-- 删除 -->
              <el-button type="danger" size="mini" @click="handleDelete(scope.row)" v-if="btnDel">删除</el-button>
              <!-- 历史 -->
              <el-button type="info" size="mini" @click="history(scope.row)" v-if="btnEdit">历史</el-button>
              <!-- 二维码 -->
              <el-button size="mini" @click="maCode(scope.row)" v-if="btnEdit"><span><i class="fa fa-qrcode" aria-hidden="true"></i></span></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="table-pageblock">
           <!-- current-page 当前页数  page-size 每页显示数 total 总页数-->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[20,50,80,100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </el-card>
      <!-- 弹窗 新增or修改 -->
      <el-dialog
        :title="textMap[dialogStatus]"
        :visible.sync="dialogFormVisible"
        :close-on-click-modal="false"
      >
        <!-- 添加、修改表单 -->
        <el-form ref="editForm" :model="editForm" label-width="80px" :rules="editFormRules">

            <el-row :gutter="24">
              <el-col :span="24">
                <!-- 所属公司 -->
                <el-form-item label="所属公司" prop="compId">
                  <el-select v-model="editForm.compId" :disabled="!isChange" auto-complete="off" placeholder="请选择"  style="width:100%;">
                    <el-option label="无" value=""></el-option>
                    <!-- 循环所有公司  公司名-公司ID -->
                    <el-option
                      v-for="(item,index) in compList"
                      :key="index"
                      :label="item.compName"
                      :value="item.compId"
                      ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item label="资产编号" prop="assetCode">
                  <el-input v-model="editForm.assetCode" :disabled="!isChange"></el-input>
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row :gutter="24">
              <el-col :span="12">
                <!-- 所属类目的ID -->
                <el-form-item label="所属类目" prop="parentId">
                  <el-select v-model="editForm.parentId" :disabled="!isChange" @change="selChildren" auto-complete="off" placeholder="请选择"  style="width:100%;">
                    <!-- 循环所有公司  类目名称-类目ID -->
                    <el-option
                      v-for="item in parentList"
                      :key="item.id"
                      :label="item.cateName"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <!-- 所属类目的ID -->
                <el-form-item label="所属分类" prop="cateCode">
                  <el-select v-model="editForm.cateCode" :disabled="!isChange" auto-complete="off" placeholder="请选择"  style="width:100%;">
                    <el-option
                      v-for="(item, index) in cateList"
                      :key="index"
                      :label="item.cateName"
                      :value="item.cateCode"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
              <el-col :span="12">
                <el-form-item label="资产名称" prop="assetName">
                  <el-input v-model="editForm.assetName" :disabled="!isChange"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="硬件编号" prop="hardwareCode">
                  <el-input v-model="editForm.hardwareCode" :disabled="!isChange"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

          <div v-show="onChange">
            <el-row :gutter="24">
              <el-col :span="12" v-show="changeStatus">
                <el-form-item label="资产状态" prop="assetStatus">
                  <el-select v-model="editForm.assetStatus" style="width:100%;">
                    <el-option label="占用" value="1"></el-option>
                    <el-option label="空闲" value="2"></el-option>
                    <el-option label="维修" value="3"></el-option>
                    <el-option label="报废" value="4"></el-option>
                    <el-option label="停用" value="5"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-show="changeUserId">
                <el-form-item label="归属人" prop="user">
                  <el-autocomplete
                    v-model="editForm.user"
                    :fetch-suggestions="querySearchAsync"
                    placeholder="请输入姓名"
                    @select="selectUserId"
                    style="width:100%;"
                    clearable
                  >
                  <template slot-scope="{ item }">
                    <div class="selName">
                      <span>{{ item.compName }} - {{ item.deptName }}</span>
                      <span>{{ item.userName }}</span>
                      <span>[{{ item.userId }}]</span>
                    </div>
                  </template>
                </el-autocomplete>
                </el-form-item>
              </el-col>

              <el-col :span="12" v-show="shNowUser">
                 <el-form-item label="当前归属">
                  <el-input v-model="nowUser" disabled></el-input>
                 </el-form-item>
              </el-col>
            </el-row>
          </div>

            <el-form-item label="放置地址" prop="address">
              <el-input v-model="editForm.address" :disabled="!isChange"></el-input>
            </el-form-item>
            <el-row :gutter="24">
              <el-col :span="12">
                <el-form-item label="购买金额" prop="buyMoney">
                  <el-input v-model="editForm.buyMoney" :disabled="!isChange" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                    <template slot="prepend">￥</template>
                    <template slot="append">元</template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="购买日期" prop="buyTime">
                  <el-date-picker
                    style="width:100%;"
                    v-model="editForm.buyTime"
                    type="date"
                    :disabled="!isChange"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 备注说明 输入长度限制20-->
            <el-form-item label="备注说明" prop="note">
              <el-input
                type="textarea"
                placeholder="备注说明（150字以内）"
                maxlength="150"
                :rows="3"
                v-model="editForm.note"
                :disabled="!isChange"
              ></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- 取消 关闭弹窗 -->
          <el-button @click.native="dialogFormVisible=false">取消</el-button>
          <!-- 添加 初始化弹窗表单数据 -->
          <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">添加</el-button>
          <!-- 修改 初始化弹窗表单数据 -->
          <el-button v-else type="primary" @click="editData">修改</el-button>
        </div>
      </el-dialog>

      <el-dialog title="操作记录" :visible.sync="modalVisible" width="600px">
        <div class="assetLog">
          <el-table
            :data="historyLog"
            border
            style="width: 100%">
            <!-- 处理人 -->
            <el-table-column prop="createUserId" label="处理人" align="center" width="100"></el-table-column>
            <!-- 处理日期 时间格式过滤 -->
            <el-table-column label="处理日期" align="center" width="120">
              <template slot-scope="scope">{{ scope.row.createTime | filterTime }}</template>
            </el-table-column>
            <el-table-column align="center" label="处理类型" width="120" prop="operation"></el-table-column>
            <el-table-column :show-overflow-tooltip="true"
              prop="note"
              label="备注说明">
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>

      <el-dialog title="Excel文件上传" :visible.sync="fileVisible" width="600px">
         <div class="fileAsset">
            <el-form>
              <el-form-item label="选择文件">
                <input type="file" name="files" id="file" @change="verificationPicFile"/>
                <el-button type="primary" size="small" @click="fileAssetExcel">确认上传</el-button>
                <a class="down-btn" href="/static/file/assets.xlsx" download>模板下载</a>
              </el-form-item>
            </el-form>
            <p>友情提示：</p>
            <p>1、此操作为高风险操作，因此操作导致的数据问题，后果自负；</p>
            <p>2、只能上传xls/xlsx文件，且不超过2M。</p>
         </div>
      </el-dialog>

      <el-dialog title="二维码" :visible.sync="codeVisible" width="462px">
        <div id="codeAsset" class="codeAsset" ref="codeMa">
          <h5>IT固定资产</h5>
          <div class="assetInfo">
            <ul>
              <li>单位：Certusnet - {{auser.compName}}</li>
              <li>日期：{{new Date() | filterTime }}</li>
              <li>责任人：{{auser.userName}} [{{auser.userId === '' ? '无' : auser.userId}}]</li>
              <li>部门：{{auser.deptName}}</li>
              <li>资产类型：{{info.cateName}}</li>
              <li>资产编码：{{info.assetCode}}</li>
              <li>SN：{{info.hardwareCode === '' ? '无' : info.hardwareCode}}</li>
            </ul>
          </div>
          <div id="qrcode" ref="qrcode"></div>
        </div>
        <el-button size="mini" icon="el-icon-picture-outline" class="imgBtn" @click="downImg">图片</el-button>
        <el-button size="mini" icon="el-icon-printer" class="printBtn" v-print="'codeAsset'">打印</el-button>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// 引入时间格式化插件
import moment from 'moment';
import QRCode from 'qrcodejs2';
// 引入html2Canvas
import html2canvas from 'html2canvas';
import { _debounce } from '@/public/debounce.js';

export default {
  name: 'assetsTable',
  // 父组件传值子组件
  props: {
    // 按钮级权限
    btns: {
      type: Object
    }
  },
  components: { QRCode },
  // 无白屏刷新方法注入
  inject: ['reload'],

  // 当前页面数据
  data () {
    return {
      // 离职人员列表
      // quitList: [],
      // 调岗人员列表
      // mobilizeList: [],
      auser: {},
      info: {},
      // 按钮显示隐藏  - 默认值
      btnSel: true,
      btnDel: true,
      btnUpload: true,
      btnDown: true,
      btnAdd: true,
      btnEdit: true,

      // 搜索条件
      formInline: {
        compId: '',
        cateCode: '',
        assetCode: '',
        assetName: '',
        assetStatus: '',
        userId: '',
        updateTime: []
      },

      // 所有公司数据
      compList: [],

      // 所有员工数据
      usersAll: [],

      // 模糊搜索
      restaurants: [],
      state: '',
      timeout: null,

      // 列表数据
      assetsData: [{}],
      // 当前页
      currentPage: 1,
      // 当前数
      pageSize: 20,
      // 总条目数
      total: 20,

      // 弹窗类别
      dialogStatus: '',
      // 弹窗标题
      textMap: {
        edit: '修改信息',
        create: '添加信息'
      },
      // 弹窗是否显示
      dialogFormVisible: false,

      // 列表选中列
      sels: [],

      // 编辑界面输入框校验规则
      editFormRules: {
        // 所属公司
        compId: [{ required: true, message: '请选择所属公司', trigger: 'change' }],
        // 资产名称
        assetName: [{ required: true, message: '请输入资产名称', trigger: 'blur' }],
        // 购买时间
        buyTime: [{ required: true, message: '请选择购买时间', trigger: 'change' }],
        // 购买金额
        buyMoney: [{ required: true, message: '请输入购买金额', trigger: 'blur' }],
        // 所属分类
        cateCode: [{ required: true, message: '请选择所属分类', trigger: 'change' }],
        // 归属人
        user: [{ required: true, message: '请选择归属人', trigger: 'change' }],
        // 放置地址
        address: [{ required: true, message: '请输入放置地址', trigger: 'blur' }],
        // 资产状态
        assetStatus: [{ required: true, message: '请选择资产状态', trigger: 'change' }]
      },

      // 界面默认数据
      editForm: {
        // 所属公司
        compId: '',
        // 所属类目
        parentId: '',
        // 所属分类
        cateCode: '',
        // 资产编号
        assetCode: '',
        // 资产名称
        assetName: '',
        // 硬件编号
        hardwareCode: '',
        // 归属人
        user: '',
        // 购买金额
        buyMoney: '',
        // 购买时间
        buyTime: '',
        // 资产状态
        assetStatus: '',
        // 放置地址
        address: '',
        // 备注说明
        note: ''
      },

      // 当前归属
      nowUser: '',

      // 父级数据
      parentList: [],

      // 子级数据
      childrenList: [],

      // 根据父级选中获取对应子级数据
      cateList: [],

      isChange: true,
      onChange: true,
      changeStatus: true,
      changeUserId: true,

      // 当前归属是否显示
      shNowUser: true,

      // 历史记录
      modalVisible: false,
      historyLog: [],

      // Excel文件上传
      fileVisible: false,

      // 二维码生成
      codeVisible: false
    };
  },

  // 实例创建后执行
  created () {
    // 按钮级授权
    this.authorization(this.$store.state.btns);

    // 加载分页数据
    this.getAssetsDataByPage();

    // 获取所有公司
    this.getcompList();

    // 获取所有员工数据
    this.getUsersAll();

    // 获取资产类目 - 父级数据
    this.getParent();

    // 获取本月调岗员工
    // this.getPostUsers();

    // 获取本月离职员工
    // this.getQuitUsers();
  },

  // 监听
  watch: {
    // 按钮权限数据
    btns (val, oldVal) {
      // 刷新当前页
      this.reload();
    }
  },

  // 过滤器
  filters: {
    // 时间显示过滤
    filterTime (value) {
      return moment(value).format('YYYY-MM-DD');
    },

    filterTimes (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '' : moment(value).format('YYYY-MM-DD HH:mm:ss');
    }
  },

  mounted () {
    this.restaurants = this.loadAll();
  },

  methods: {

    // 图片下载
    downImg () {
      let _this = this;
      html2canvas(_this.$refs.codeMa, {
        backgroundColor: '#fff'
      }).then(canvas => {
        let imgData = canvas.toDataURL('image/jpeg');
        _this.fileDownload(imgData);
      });
    },

    // 下载图片
    fileDownload (downloadUrl) {
      let _this = this;
      let aLink = document.createElement('a');
      aLink.style.display = 'none';
      aLink.href = downloadUrl;
      aLink.download = _this.info.assetCode + '.png';
      // 触发点击-然后移除
      document.body.appendChild(aLink);
      aLink.click();
      document.body.removeChild(aLink);
    },

    // 获取调岗人员
    // getPostUsers () {
    //   let _this = this;
    //   let params = {
    //     type: 1,
    //     date: moment(new Date()).format('YYYY-MM')
    //   };
    //   _this.$http.post('api/findPersonnelList', params).then(res => {
    //     let {code, datas} = res;
    //     if (code === 0) {
    //       _this.mobilizeList = datas;
    //     }
    //   }).catch(err => {
    //     if (err === undefined) {
    //       _this.$message({
    //         message: '服务器响应异常！',
    //         type: 'error'
    //       });
    //       return false;
    //     }
    //   });
    // },

    // 获取离职人员
    // getQuitUsers () {
    //   let _this = this;
    //   let params = {
    //     type: 2,
    //     date: moment(new Date()).format('YYYY-MM')
    //   };
    //   _this.$http.post('api/findPersonnelList', params).then(res => {
    //     let {code, datas} = res;
    //     if (code === 0) {
    //       _this.quitList = datas;
    //     }
    //   }).catch(err => {
    //     if (err === undefined) {
    //       _this.$message({
    //         message: '服务器响应异常！',
    //         type: 'error'
    //       });
    //       return false;
    //     }
    //   });
    // },

    // 快速复制
    // copyLink () {
    //   let _this = this;
    //   let clipboardObj = new _this.$clipboard('.copy');
    //   clipboardObj.on('success', function () {
    //     return true;
    //   });
    //   clipboardObj.on('error', function () {
    //     return false;
    //   });
    // },

    qrcode (link) {
      document.getElementById('qrcode').innerHTML = '';
      // eslint-disable-next-line no-unused-vars
      let qrcode = new QRCode('qrcode', {
        width: 120, // 设置宽度
        height: 120, // 设置高度
        text: link
      });
    },

    // 按钮级授权
    authorization (data) {
      let _this = this;
      for (let i in data) {
        if (data['sel'] === 0) {
          _this.btnSel = false;
        }
        if (data['add'] === 0) {
          _this.btnAdd = false;
        }
        if (data['del'] === 0) {
          _this.btnDel = false;
        }
        if (data['upload'] === 0) {
          _this.btnUpload = false;
        }
        if (data['down'] === 0) {
          _this.btnDown = false;
        }
        if (data['edit'] === 0) {
          _this.btnEdit = false;
        }
        return i;
      }
    },

    // 获取所有公司
    getcompList () {
      let _this = this;
      // 获取所有公司数据
      _this.$http.get('api/findAllCompNoPage').then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.compList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 获取所有员工数据
    getUsersAll () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          for (let i = datas.length; i--;) {
            _this.usersAll.push({
              compName: datas[i].compName,
              deptName: datas[i].deptName,
              userId: datas[i].userId,
              userName: datas[i].userName
            });
          };
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 加载全部员工数据
    loadAll () {
      return this.usersAll;
    },

    // 自动检索匹配
    querySearchAsync (queryString, cb) {
      let _this = this;
      let restaurants = _this.restaurants;
      let results = queryString ? restaurants.filter(_this.createStateFilter(queryString)) : restaurants;
      clearTimeout(_this.timeout);
      _this.timeout = setTimeout(() => {
        cb(results);
      }, 300 * Math.random());
    },

    // 查询
    createStateFilter (queryString) {
      return (state) => {
        return (state.userName.indexOf(queryString) === 0);
      };
    },

    // 选中赋值
    handleSelect (item) {
      this.formInline.user = item.userName + ' [' + item.userId + ']';
    },

    // 获取所有父级
    getParent () {
      let _this = this;
      // 获取资产分类  - 父级数据
      _this.$http.post('api/findAllCate').then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          for (let i = datas.length; i--;) {
            if (datas[i].parentId === 0) {
              _this.parentList.push({
                id: datas[i].id,
                cateName: datas[i].cateName
              });
            } else {
              _this.childrenList.push({
                cateName: datas[i].cateName,
                cateCode: datas[i].cateCode
              });
            }
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 根据所选父级ID 获取对应子级数据列表
    selChildren () {
      let _this = this;
      let parentId = _this.editForm.parentId;

      let params = {
        parentId: parentId
      };

      _this.cateList = [];

      _this.$http.post('api/findCateByParentId', params).then(res => {
        let {code, datas} = res;
        if (code === 0) {
          for (let i = datas.length; i--;) {
            _this.cateList.push({
              cateName: datas[i].cateName,
              cateCode: datas[i].cateCode
            });
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 新增时 选择员工
    selectUserId (item) {
      sessionStorage.setItem('oldUser', item.userName + ' [' + item.userId + ']');
      this.editForm.user = item.userName + ' [' + item.userId + ']';
    },

    // 显示编辑界面
    editHandle: function (row, type) {
      let _this = this;
      // 弹窗类型
      _this.dialogStatus = 'edit';
      // 弹窗显示状态
      _this.dialogFormVisible = true;
      // 弹窗表单初始化显示数据
      _this.editForm = Object.assign({}, row);
      // 资产状态
      _this.editForm.assetStatus = row.assetStatus.toString();
      // 资产父级-子级 数据集
      _this.selParentChildren(row.cateCode);

      // 修改
      if (type === 1) {
        _this.isChange = true;
        // 隐藏变更内容
        _this.onChange = false;
        _this.changeStatus = false;
        _this.changeUserId = false;
        _this.shNowUser = false;
        _this.editForm.user = row.userName + '  [' + row.userId + ']';
      }
      // 状态
      if (type === 2) {
        _this.isChange = false;
        _this.onChange = true;
        _this.changeStatus = true;
        _this.editForm.user = row.userName + '  [' + row.userId + ']';
        sessionStorage.setItem('assetStatus', row.assetStatus);
        _this.changeUserId = false;
        _this.shNowUser = false;
      }
      // 归属
      if (type === 3) {
        _this.isChange = false;
        _this.onChange = true;
        _this.changeUserId = true;
        _this.shNowUser = true;
        _this.nowUser = row.userName === null ? '[无]' : row.userName + '  [' + row.userId + ']';
        sessionStorage.setItem('assetUser', row.userName + '  [' + row.userId + ']');
        _this.changeStatus = false;
      }
    },

    // 获取父级-子级别 数据集
    selParentChildren: function (code) {
      let childrenCode = code;
      let _this = this;
      _this.$http.post('api/findAllCate').then(res => {
        let {code, datas} = res;
        if (code === 0) {
          for (let i = datas.length; i--;) {
            if (datas[i].parentId !== 0) {
              if (datas[i].cateCode === childrenCode) {
                _this.editForm.parentId = datas[i].parentId;
                _this.selChildren();
              }
            }
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 显示新增界面
    addHandle: function () {
      let _this = this;
      // 弹窗类型
      _this.dialogStatus = 'create';
      // 弹窗显示状态
      _this.dialogFormVisible = true;
      // 重置新增界面默认数据
      _this.editForm = {
        // 所属公司
        compId: '',
        // 所属类目
        parentId: '',
        // 所属类目
        cateCode: '',
        // 资产编号
        assetCode: '',
        // 资产名称
        assetName: '',
        // 硬件编号
        hardwareCode: '',
        // 归属人
        userId: '',
        // 购买金额
        buyMoney: '',
        // 购买时间
        buyTime: '',
        // 资产状态
        assetStatus: '',
        // 放置地址
        address: '',
        // 备注说明
        note: ''
      };
      _this.isChange = true;
      _this.onChange = true;
      _this.changeStatus = true;
      _this.changeUserId = true;
      _this.shNowUser = false;
    },

    // 查询
    selHandle: function () {
      let _this = this;
      let user = _this.formInline.user === null || _this.formInline.user === undefined ? '' : _this.formInline.user;

      // 收集请求数据
      let params = {
        compId: _this.formInline.compId === null ? '' : _this.formInline.compId,
        cateCode: _this.formInline.cateCode === null ? '' : _this.formInline.cateCode,
        assetCode: _this.formInline.assetCode === null ? '' : _this.formInline.assetCode,
        assetName: _this.formInline.assetName === null ? '' : _this.formInline.assetName,
        assetStatus: _this.formInline.assetStatus === null ? '' : _this.formInline.assetStatus,
        userId: user === '' ? '' : user.slice(user.indexOf('[') + 1, user.indexOf(']')),
        beginTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[0]).format('YYYY-MM-DD') : '',
        endTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[1]).format('YYYY-MM-DD') : '',
        pageNum: _this.currentPage,
        pageSize: _this.pageSize
      };

      // 根据ID获取分页数据
      _this.$http.raw('api/findAassetList', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          // 总页数
          _this.total = datas.total;
          // 数据结果集
          _this.assetsData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && _this.currentPage !== 1) {
            // 当前页减一
            _this.currentPage -= 1;
            // 调用自己
            _this.getAssetsDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 修改
    editData: _debounce(function () {
      let _this = this;
      _this.$nextTick(() => {
      // 判断是否通过验证规则验证
        _this.$refs['editForm'].validate(valid => {
          if (valid) {
            let userId = _this.editForm.user;
            if (userId.indexOf('[') && userId.indexOf(']')) {
              userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
            }
            // 收集请求数据
            let params = {
              id: _this.editForm.id,
              // 所属公司
              compId: _this.editForm.compId,
              // 所属类目
              cateCode: _this.editForm.cateCode,
              // 资产编号
              assetCode: _this.editForm.assetCode,
              // 资产名称
              assetName: _this.editForm.assetName,
              // 硬件编号
              hardwareCode: _this.editForm.hardwareCode,
              // 归属人
              userId: userId,
              // 购买金额
              buyMoney: _this.editForm.buyMoney,
              // 购买时间
              buyTime: moment(_this.editForm.buyTime).format('YYYY-MM-DD'),
              // 资产状态
              assetStatus: _this.editForm.assetStatus,
              // 放置地址
              address: _this.editForm.address,
              // 备注说明
              note: _this.editForm.note
            };
            let user = {
              userId: userId
            };

            // 通过用户工号判断
            _this.$http.post('api/checkUserByUserId', user).then(res => {
              let { code, datas } = res;
              // 判断Code状态
              if (code === 0) {
                if (datas) {
                  // 修改角色信息
                  _this.$http.raw('api/updateAsset', params).then(res => {
                    let { code } = res;
                    // 判断Code状态
                    if (code === 0) {
                      // 判断修改状态 /  归属
                      if (_this.changeStatus) {
                        let stat = sessionStorage.getItem('assetStatus');
                        switch (stat.length > 0) {
                          case stat === '1':
                            stat = '占用';
                            break;
                          case stat === '2':
                            stat = '空闲';
                            break;
                          case stat === '3':
                            stat = '维修';
                            break;
                          case stat === '4':
                            stat = '报废';
                            break;
                          case stat === '5':
                            stat = '停用';
                            break;
                        }
                        let nstat = _this.editForm.assetStatus;
                        switch (nstat.length > 0) {
                          case nstat === '1':
                            nstat = '占用';
                            break;
                          case nstat === '2':
                            nstat = '空闲';
                            break;
                          case nstat === '3':
                            nstat = '维修';
                            break;
                          case nstat === '4':
                            nstat = '报废';
                            break;
                          case nstat === '5':
                            nstat = '停用';
                            break;
                        }
                        let changes = {
                          assetCode: _this.editForm.assetCode,
                          operation: '状态变更',
                          note: '原始值：' + stat + ' 变更后：' + nstat
                        };
                        _this.$http.raw('api/insertAssetRecord', changes).then().catch(err => {
                          if (err === undefined) {
                            _this.$message({
                              message: '服务器响应异常！',
                              type: 'error'
                            });
                            return false;
                          }
                        });
                      }
                      if (_this.changeUserId) {
                        let oluser = sessionStorage.getItem('assetUser') === 'null  []' ? '[无]' : sessionStorage.getItem('assetUser');
                        let changes = {
                          assetCode: _this.editForm.assetCode,
                          operation: '归属人变更',
                          note: '原始值：' + oluser + ' 变更后：' + sessionStorage.getItem('oldUser')
                        };
                        _this.$http.raw('api/insertAssetRecord', changes).then().catch(err => {
                          if (err === undefined) {
                            _this.$message({
                              message: '服务器响应异常！',
                              type: 'error'
                            });
                            return false;
                          }
                        });
                      }
                      _this.$message({
                        message: '修改成功！',
                        type: 'success'
                      });
                      _this.$refs['editForm'].resetFields();
                      _this.dialogFormVisible = false;
                      // 刷新列表
                      _this.getAssetsDataByPage();
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                } else {
                  _this.$message({
                    message: '归属人工号不存在！',
                    type: 'error'
                  });
                }
              }
            }).catch(err => {
              if (err === undefined) {
                _this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        });
      });
    }, 200),

    // 添加
    createData: _debounce(function () {
      let _this = this;
      _this.$nextTick(() => {
        // 判断是否通过验证规则验证
        _this.$refs['editForm'].validate(valid => {
          if (valid) {
            let userId = _this.editForm.user;
            if (userId.indexOf('[') && userId.indexOf(']')) {
              userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
            }
            // 收集请求数据
            let params = {
              // 所属公司
              compId: _this.editForm.compId === null ? '' : _this.editForm.compId,
              // 所属类目
              cateCode: _this.editForm.cateCode === null ? '' : _this.editForm.cateCode,
              // 资产编号
              assetCode: '服务端自动生成编号',
              // 资产名称
              assetName: _this.editForm.assetName === null ? '' : _this.editForm.assetName,
              // 硬件编号
              hardwareCode: _this.editForm.hardwareCode === null ? '' : _this.editForm.hardwareCode,
              // 归属人
              userId: userId,
              // 购买金额
              buyMoney: _this.editForm.buyMoney === null ? '' : _this.editForm.buyMoney,
              // 购买时间
              buyTime: _this.editForm.buyTime === null ? '' : moment(_this.editForm.buyTime).format('YYYY-MM-DD'),
              // 资产状态
              assetStatus: _this.editForm.assetStatus === null ? '' : _this.editForm.assetStatus,
              // 放置地址
              address: _this.editForm.address === null ? '' : _this.editForm.address,
              // 备注说明
              note: _this.editForm.note === null ? '' : _this.editForm.note
            };

            let user = {
              userId: userId
            };

            // 通过用户工号判断
            _this.$http.post('api/checkUserByUserId', user).then(res => {
              let { code, datas } = res;
              // 判断Code状态
              if (code === 0) {
                if (datas) {
                  // 添加资产信息
                  _this.$http.raw('api/insertAsset', params).then(res => {
                    let { code } = res;
                    // 判断Code状态
                    if (code === 0) {
                      let acode = JSON.parse(res.datas);
                      let changes = {
                        assetCode: acode.assetCode,
                        operation: '资产入库',
                        note: '领用人：' + _this.editForm.user
                      };
                      _this.$http.raw('api/insertAssetRecord', changes).then().catch(err => {
                        if (err === undefined) {
                          _this.$message({
                            message: '服务器响应异常！',
                            type: 'error'
                          });
                          return false;
                        }
                      });
                      _this.$message({
                        message: '添加成功！资产编号：' + acode.assetCode,
                        type: 'success',
                        showClose: true,
                        duration: 0
                      });
                      _this.$refs['editForm'].resetFields();
                      _this.dialogFormVisible = false;
                      // 刷新列表
                      _this.getAssetsDataByPage();
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                } else {
                  _this.$message({
                    message: '归属人工号不存在！',
                    type: 'error'
                  });
                }
              }
            }).catch(err => {
              if (err === undefined) {
                _this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        });
      });
    }, 200),

    // 删除
    handleDelete (data) {
      let _this = this;
      // 删除二次确认
      _this.$confirm('确认删除选中的信息吗？', '提示', {
        type: 'warning'
      }).then(() => {
        let params = [data.id];
        _this.$http.raw('api/batchDelAsset', params).then(res => {
          let { code } = res;
          if (code === 0) {
            _this.$message({
              type: 'success',
              message: '删除成功！'
            });
            // 刷新列表
            _this.getAssetsDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            _this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }).catch(() => {
        _this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 全选、单选、多选
    selsChange: function (sels) {
      this.sels = sels;
    },

    // 批量删除
    batchRemove: function () {
      let _this = this;
      // 判断是否选择数据
      if (!_this.sels.length) {
        _this.$message.warning('您还没选择任何数据！');
        return;
      }
      // 删除二次确认
      _this.$confirm('确认删除选中的信息吗？', '提示', {
        type: 'warning'
      }).then(() => {
        let params = [];
        // 获取所有勾选ID
        _this.sels.map(item => {
          return params.push(item.id);
        });
        // 批量删除
        _this.$http.raw('api/batchDelAsset', params).then(res => {
          let { code } = res;
          // 判断Code状态
          if (code === 0) {
            _this.$message({
              type: 'success',
              message: '批量删除成功！'
            });
            // 刷新列表
            _this.getAssetsDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            _this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }).catch(() => {
        _this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 下载
    getAssetExcel () {
      let _this = this;
      let user = _this.formInline.user === null || _this.formInline.user === undefined ? '' : _this.formInline.user;

      // 收集请求信息
      let params = {
        compId: _this.formInline.compId === null ? '' : _this.formInline.compId,
        cateCode: _this.formInline.cateCode === null ? '' : _this.formInline.cateCode,
        assetCode: _this.formInline.assetCode === null ? '' : _this.formInline.assetCode,
        assetName: _this.formInline.assetName === null ? '' : _this.formInline.assetName,
        assetStatus: _this.formInline.assetStatus === null ? '' : _this.formInline.assetStatus,
        userId: user === '' ? '' : user.slice(user.indexOf('[') + 1, user.indexOf(']')),
        beginTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[0]).format('YYYY-MM-DD') : '',
        endTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[1]).format('YYYY-MM-DD') : ''
      };

      // 根据查询下载数据
      _this.$http.download('api/downAsset?compId=' + params.compId + '&cateCode=' + params.cateCode + '&assetCode=' + params.assetCode + '&assetName=' + params.assetName + '&userId=' + params.userId + '&assetStatus=' + params.assetStatus + '&beginTime=' + params.beginTime + '&endTime=' + params.endTime).then(res => {
        let blob = new Blob([res], {type: res.type});
        let downloadElement = document.createElement('a');
        let href = window.URL.createObjectURL(blob); // 创建下载的链接
        downloadElement.href = href;
        downloadElement.download = '资产数据.xlsx'; // 下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); // 点击下载
        document.body.removeChild(downloadElement); // 下载完成移除元素
        window.URL.revokeObjectURL(href); // 释放blob对象
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    showFile () {
      let _this = this;
      _this.fileVisible = true;
    },

    // 文件判断
    verificationPicFile () {
      let _this = this;
      let file = document.querySelector('input[type=file]').files[0];
      let fileTypes = ['.xls', '.xlsx'];
      let fileMaxSize = 2048;// 2M
      let isNext = false;

      let fileName = file.name;
      let fileSize = file.size;

      if (fileName) {
        let fileEnd = fileName.substring(fileName.indexOf('.'));
        for (let i = fileTypes.length; i--;) {
          if (fileTypes[i] === fileEnd) {
            isNext = true;
            break;
          }
        }
        if (!isNext) {
          _this.$message({
            message: '不接受此文件类型！',
            type: 'error'
          });
          document.querySelector('input[type=file]').value = '';
          return false;
        }
      }
      if (fileName) {
        let size = fileSize / 2048;
        if (size > fileMaxSize) {
          _this.$message({
            message: '文件大小不能大于2M！',
            type: 'error'
          });
          document.querySelector('input[type=file]').value = '';
          return false;
        } else if (size <= 0) {
          _this.$message({
            message: '文件大小不能为0M！',
            type: 'error'
          });
          document.querySelector('input[type=file]').value = '';
          return false;
        }
      }
    },

    // 文件上传
    fileAssetExcel () {
      let _this = this;
      let file = document.querySelector('input[type=file]').files[0];

      if (file === null || file === undefined || file === '') {
        _this.$message({
          message: '未选择任何文件！',
          type: 'error'
        });
      } else {
        let formData = new FormData(); // 创建form对象
        formData.append('uploadFile', file);
        _this.$http.upload('api/uploadAsset', formData).then(res => {
          let { code } = res;
          if (code === 0) {
            _this.$message({
              type: 'success',
              message: '上传成功！'
            });
            _this.fileVisible = false;
            // 刷新列表
            _this.getAssetsDataByPage();
          }
        }).catch(err => {
          if (err === undefined) {
            _this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }
    },

    // 操作历史
    history: function (row) {
      let _this = this;
      _this.modalVisible = true;
      let params = {
        assetCode: row.assetCode
      };
      _this.$http.post('api/findAssetRecordList', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          _this.historyLog = res.datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 生成二维码
    maCode: function (row) {
      let _this = this;
      _this.codeVisible = true;
      _this.info = row;
      let link = 'http://' + document.domain + '/home/assetInfo/' + row.assetCode;
      _this.$nextTick(function () {
        _this.qrcode(link);
      });

      let params = {
        assetCode: row.assetCode
      };
      _this.$http.post('api/findAssetInfos', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          _this.auser = datas.users[0];
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 刷新页面数据
    getAssetsDataByPage () {
      let _this = this;
      let user = _this.formInline.user === null || _this.formInline.user === undefined ? '' : _this.formInline.user;

      // 收集请求信息
      let params = {
        compId: _this.formInline.compId === null ? '' : _this.formInline.compId,
        cateCode: _this.formInline.cateCode === null ? '' : _this.formInline.cateCode,
        assetCode: _this.formInline.assetCode === null ? '' : _this.formInline.assetCode,
        assetName: _this.formInline.assetName === null ? '' : _this.formInline.assetName,
        assetStatus: _this.formInline.assetStatus === null ? '' : _this.formInline.assetStatus,
        userId: user === '' ? '' : user.slice(user.indexOf('[') + 1, user.indexOf(']')),
        beginTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[0]).format('YYYY-MM-DD') : '',
        endTime: _this.formInline.updateTime.length > 0 ? moment(_this.formInline.updateTime[1]).format('YYYY-MM-DD') : '',
        pageNum: _this.currentPage,
        pageSize: _this.pageSize
      };
      // 获取分页数据
      _this.$http.raw('api/findAassetList', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.total = datas.total;
          _this.assetsData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && _this.currentPage !== 1) {
            // 当前页减一
            _this.currentPage -= 1;
            // 调用自己
            _this.getAssetsDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 每页显示的条数改变
    handleSizeChange (val) {
      this.pageSize = val;
      // 调用刷新页面
      this.getAssetsDataByPage();
    },
    // 当前页码
    handleCurrentChange (val) {
      this.currentPage = val;
      // 调用
      this.getAssetsDataByPage();
    }
  }
};
</script>

<style lang='scss' scoped>
@import './index.scss';
</style>
